﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace PhotoGallery
{
    public partial class Gallery : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            LoadImages(0);
        }

        protected void PrevBtn_Click(object sender, EventArgs e)
        {
            startIndexLabel.InnerText = ((int)Session["startIndex"]).ToString();
            Session["startIndex"] = (int)Session["startIndex"] - 4;
            startIndexLabel.InnerText += " "+ ((int)Session["startIndex"]).ToString();
            LoadImages((int)Session["startIndex"]);
        }


        protected void NextBtn_Click(object sender, EventArgs e)
        {
            startIndexLabel.InnerText = ((int)Session["startIndex"]).ToString();
            Session["startIndex"] = (int)Session["startIndex"] + 4;
            startIndexLabel.InnerText +=" " + ((int)Session["startIndex"]).ToString();
            LoadImages((int)Session["startIndex"]);
        }

        private void LoadImages(int currentIndex)
        {
           
            if (currentIndex < (Session["images"] as List<string>).Count)
                picture1.ImageUrl = @"~/images/" + (Session["images"] as List<string>)[currentIndex];
            else
                picture1.ImageUrl = "";

            if (currentIndex + 1 < (Session["images"] as List<string>).Count)
                picture2.ImageUrl = @"~/images/" + (Session["images"] as List<string>)[currentIndex + 1];
            else
                picture2.ImageUrl = "";

            if (currentIndex + 2 < (Session["images"] as List<string>).Count)
                picture3.ImageUrl = @"~/images/" + (Session["images"] as List<string>)[currentIndex + 2];
            else
                picture3.ImageUrl = "";

            if (currentIndex + 3 < (Session["images"] as List<string>).Count)
                picture4.ImageUrl = @"~/images/" + (Session["images"] as List<string>)[currentIndex + 3];
            else
                picture4.ImageUrl = "";
        }

    }
}